/*
 * Created on Apr 27, 2006
 */
package net.amsoft.iservice.management.util;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

/**
 * @author mukta
 */
public class IBrokerConstants {
    
    private static Logger logger = Logger.getLogger(IBrokerConstants.class);
	public static ResourceBundle IBrokerBundle = ResourceBundle.getBundle("ibrokerResources");
	
    // Captions for Administrator Login Page
    public static final String LOGIN_TITLE = "ibroker.login.title";
    public static final String LOGIN_INAME = "ibroker.login.iname";
    public static final String LOGIN_BROKER = "ibroker.login.broker";
    public static final String LOGIN_SERVICE = "ibroker.login.service";
    public static final String LOGIN_LOGIN = "ibroker.login.login";
    public static final String LOGIN_CANCEL = "ibroker.login.cancel";

    // Captions for Customization Page
    public static final String CUSTOMIZATION_TITLE = "ibroker.customization.title";
    public static final String CUSTOMIZATION_CHANGE_LOGO = "ibroker.customization.changeLogo";
    public static final String CUSTOMIZATION_CHANGE_ADBANNER = "ibroker.customization.changeAdBanner";
    public static final String CUSTOMIZATION_CHANGE_RELATEDNEWS = "ibroker.customization.changeRelatedNews";
    public static final String CUSTOMIZATION_CHANGE_LINKS = "ibroker.customization.changeLinks";
    public static final String CUSTOMIZATION_CHANGE_STYLESHEET = "ibroker.customization.changeStylesheet";
    
    // Captions for New Logo Image Upload Page
    public static final String CHANGE_LOGO_TITLE = "ibroker.changeLogo.title";
    public static final String CHANGE_LOGO_MESSAGE = "ibroker.changeLogo.message";
    public static final String CHANGE_LOGO_FILE = "ibroker.changeLogo.file";
    
    // Captions for New Ad-Banner Upload Page
    public static final String CHANGE_ADBANNER_TITLE = "ibroker.changeAdBanner.title";
    public static final String CHANGE_ADBANNER_MESSAGE = "ibroker.changeAdBanner.message";
    public static final String CHANGE_ADBANNER_FILE = "ibroker.changeAdBanner.file";
    public static final String CHANGE_ADBANNER_LINK = "ibroker.changeAdBanner.link";
    
    // Captions for New Related-News Image Upload Page
    public static final String CHANGE_RELATEDNEWS_TITLE = "ibroker.changeRelatedNews.title";
    public static final String CHANGE_RELATEDNEWS_MESSAGE = "ibroker.changeRelatedNews.message";
    public static final String CHANGE_RELATEDNEWS_FILE = "ibroker.changeRelatedNews.file";
    
    // Captions for New Links Upload Page
    public static final String CHANGE_LINKS_TITLE = "ibroker.changeLinks.title";
    public static final String CHANGE_LINKS_MESSAGE = "ibroker.changeLinks.message";
    public static final String CHANGE_LINKS_NAME = "ibroker.changeLinks.name";
    public static final String CHANGE_LINKS_ADDRESS = "ibroker.changeLinks.address";
    
    // Captions for New Stylesheet Upload Page
    public static final String CHANGE_STYLESHEET_TITLE = "ibroker.changeStylesheet.title";
    public static final String CHANGE_STYLESHEET_MESSAGE = "ibroker.changeStylesheet.message";
    
    // Captions for New Logo Image Preview Page
    public static final String PREVIEW_LOGO_TITLE = "ibroker.previewLogo.title";
    public static final String PREVIEW_LOGO_MESSAGE = "ibroker.previewLogo.message";
    
    // Captions for New Ad-Banner Image Preview Page
    public static final String PREVIEW_ADBANNER_TITLE = "ibroker.previewAdBanner.title";
    public static final String PREVIEW_ADBANNER_MESSAGE = "ibroker.previewAdBanner.message";
    
    // Captions for New Ad-Banner Link Preview Page
    public static final String PREVIEW_ADBANNER_LINK_TITLE = "ibroker.previewAdBannerLink.title";
    public static final String PREVIEW_ADBANNER_LINK_MESSAGE = "ibroker.previewAdBannerLink.message";
    
    // Captions for New Related-News Image Preview Page
    public static final String PREVIEW_RELATEDNEWS_TITLE = "ibroker.previewRelatedNews.title";
    public static final String PREVIEW_RELATEDNEWS_MESSAGE = "ibroker.previewRelatedNews.message";
    
    // Captions for New Links Preview Page
    public static final String PREVIEW_LINKS_TITLE = "ibroker.previewLinks.title";
    public static final String PREVIEW_LINKS_MESSAGE = "ibroker.previewLinks.message";
    
    // Caption for Image file formats
    public static final String LOGO_IMAGE_FORMATS = "ibroker.logo.image.formats";
    public static final String ADBANNER_IMAGE_FORMATS = "ibroker.adBanner.image.formats";
    public static final String RELATEDNEWS_IMAGE_FORMATS = "ibroker.relatedNews.image.formats";

    // Captions for Error Messages
    public static final String IMAGE_EMPTY = "ibroker.image.empty";
    public static final String IMAGE_INVALID = "ibroker.image.invalid";
    public static final String ADBANNER_EMPTY = "ibroker.adBanner.empty";
    public static final String ADBANNER_LINK_INVALID = "ibroker.adBanner.link.invalid";
    public static final String ADBANNER_IMAGE_INVALID = "ibroker.adBanner.image.invalid";
    public static final String LINKS_EMPTY = "ibroker.links.empty";
    public static final String LINKS_INVALID = "ibroker.links.invalid";
    
    // User states
    public static final short STATE_PENDING = 0;
    public static final short STATE_ACTIVE = 1;
    public static final short STATE_BANNED = 2;
    public static final short STATE_INACTIVE = 3;

    // Forwards
    public static final String FWD_INAME_PAGE = "iname";
    public static final String FWD_CHKLOGIN = "CheckLogin";
    public static final String FWD_SUCCESS = "success";
    public static final String FWD_FAILURE = "failure";
    public static final String FWD_CANCEL = "cancel";
    public static final String FWD_ILINKS = "ilinks";
    public static final String FWD_LOGIN = "login";
    public static final String FWD_BANNER_LINK_SUCCESS = "link";

    // Errors
    public static final String ERR_INAME = "err.iname";
    public static final String ERR_INVALID = "err.invalid";
    public static final String ERR_REQUIRED = "err.required";
    public static final String ERR_GLOBAL_LOGOUT_NOT_DONE = "err.global.logout.not.done";
    public static final String ERR_UKNOWN_GLOBAL_SESSION = "err.unknown.global.session";
    public static final String ERR_AUTHN_FAILED = "err.authn.failed";
    public static final String ERR_INVALID_INAME = "err.invalid.iname";
    public static final String ERR_INVALID_ADMIN = "err.invalid.admin";
    public static final String ERR_FILE_NOT_FOUND = "err.file.not.found";
    public static final String ERR_IO_FAILED = "err.io.failed";

    // Forms
    public static final String SESSION_LOGIN_OBJ = "LoginData";

    // Success Messages
    public static final String MSG_LOGIN_SUCCESS = "msg.login.success";
    public static final String MSG_LOGOUT_SUCCESS = "msg.logout.success";

    // Service name constants
    public static final String SERVICE_ISSO = "isso";
    public static final String SERVICE_ICONTACT = "icontact";
    public static final String SERVICE_ILINK = "ilink";
    
    // Requested Authentication Contexts and Comparison type
    public static final String RAC_NAMES_LIST = IBrokerBundle.getString("rac.names.list");
    public static final String RAC_COMPARISON_TYPE = IBrokerBundle.getString("rac.comparison.type");
    
    public static final String URL_XRI_NET = IBrokerBundle.getString("xri.net.url");

    private static Hashtable ohErrors = null;
    public static Hashtable oIBrokerTable = new Hashtable();

    public static final void init()
    {
        if (ohErrors == null)
        {
            ohErrors = new Hashtable();

            // User Exceptions
            ohErrors.put(new Integer(1001), "Password does not match");
            ohErrors.put(new Integer(1000), " Email address is not valid");
            ohErrors.put(new Integer(1005), " User could not be logged in");

            // System Exceptions
            ohErrors.put(new Integer(2000), "GlobalINumber already exists ");
            ohErrors.put(new Integer(2006), "GlobalInumber does not exist");
            ohErrors.put(new Integer(2007), "Account is not active");
            ohErrors.put(new Integer(2010), "User does not belong to this IBroker");

            ohErrors.put(new Integer(2012), "IBroker could not be  created");
            ohErrors.put(new Integer(2004), "IBroker not provisioned");
            ohErrors.put(new Integer(2014), "Invalid Fields");
            ohErrors.put(new Integer(2016), "No permissions to insert the supplied Fields");
            ohErrors.put(new Integer(2017), "Data Could not be deleted");
            ohErrors.put(new Integer(2018), "Specified Operations was not performed successfully");
            ohErrors.put(new Integer(2020), "No Synonyms Found");
            ohErrors.put(new Integer(2021), "No permissions to update one or more of the specified fields");
            ohErrors.put(new Integer(2022), "Data could not be updated");
            ohErrors.put(new Integer(2028), "InSufficient Data");
            ohErrors.put(new Integer(2030), "No matching record found ");
            ohErrors.put(new Integer(2031), "IBroker already exist");
            ohErrors.put(new Integer(2034), "Iname/Inumber can't be resolved");
            ohErrors.put(new Integer(2036), "This Method is currently not implemented.");

            ohErrors.put(new Integer(101), "Duplicate");
            ohErrors.put(new Integer(102), "Parse Error");
        }
    }

    public static final String getError(int iErrorCode)
            throws NullPointerException
    {
        if (ohErrors == null)
        {
            init();
        }
        return (String) ohErrors.get(new Integer(iErrorCode));
    }

    public static final void initializeIbrokerData()
    {
        if (oIBrokerTable == null || oIBrokerTable.size() == 0)
        {
            ResourceBundle oBundle = ResourceBundle.getBundle("ibrokers");
            Enumeration oBundleKeys = oBundle.getKeys();
            while (oBundleKeys.hasMoreElements())
            {
                String sIBname = (String) oBundleKeys.nextElement();
                oIBrokerTable.put(sIBname, oBundle.getString(sIBname));
            }
        }
    }

    public static final String getSPXri(String ibrokerName)
    {
        if (oIBrokerTable == null || !oIBrokerTable.containsKey(ibrokerName))
            initializeIbrokerData();

        String sXRI = (String) oIBrokerTable.get(ibrokerName);
        logger.debug("getSPXri(): IB=" + ibrokerName + ", XRI=" + sXRI);
        return sXRI;
    }
    
    public static final String getProperty(String key)
	{
		try
		{
			return IBrokerBundle.getString(key);
		}
		catch (Exception e)
		{
			logger.debug("getProperty(): key: [" + key + "] not found");
			return "";
		}
	}

}
